home *** CD-ROM | disk | FTP | other *** search
Wrap
using System; using System.Windows.Forms; using IMSIGX; using TCIMAGELib; namespace CSharpTCImage { /// <summary> /// Summary description for Class1. /// </summary> public class CSharpTCImageTool { const short NUM_TOOLS = 1; //Toggle this to test loading buttons from .Bmp/.Res const bool boolLoadFromBmp = false; public CSharpTCImageTool() { // // TODO: Add constructor logic here // } public string Description { get { return "TurboCAD CSharp Tool"; } } public bool Run(IMSIGX.Tool theTool) { IMSIGX.IApplication gxApp; IMSIGX.IDrawing gxDr; gxApp = theTool.Application ; gxDr = gxApp.ActiveDrawing ; //MessageBox.Show ("Add your code here"); InsertPicture(gxApp, gxDr); return true; } public int GetToolInfo(out object CommandNames, out object MenuCaptions, out object StatusPrompts, out object ToolTips, out object Enabled, out object WantsUpdates) { try { string[] SCommandNames = new string[NUM_TOOLS]; string[,] SMenuCaptions = new string[NUM_TOOLS,2]; string[] SStatusPrompts = new string[NUM_TOOLS]; string[] SToolTips = new string[NUM_TOOLS]; bool[] BEnabled = new bool[NUM_TOOLS]; bool[] BWantsUpdates = new bool[NUM_TOOLS]; int[] iIndex = {0,0}; SCommandNames[0] = "Bonus|C# TCImage Tool"; SMenuCaptions.SetValue ("C# TCImage Tool",iIndex); iIndex[1] = 1; Array arTest = Array.CreateInstance (typeof(string),1,2); arTest.SetValue ("test 1", 0, 0); arTest.SetValue ("test 2", 0, 1); SMenuCaptions.SetValue ("Bonus",0,1); //SMenuCaptions[0, 1] = "Bonus"; SStatusPrompts[0] = "C# Tool prompt"; SToolTips[0] = "C# TCImage Tool tooltip"; BEnabled[0] = true; BWantsUpdates[0] = false; CommandNames = SCommandNames; MenuCaptions = SMenuCaptions; StatusPrompts = SStatusPrompts; ToolTips = SToolTips; Enabled = BEnabled; WantsUpdates = BWantsUpdates; return NUM_TOOLS; } catch(Exception e) { Console.WriteLine("An error occurred: '{0}'", e); throw; } } /// <summary> /// Public Function GetPicture(ByVal LargeImage As Boolean, ByVal MonoImage As Boolean) As Object /// </summary> public object GetPicture(bool LargeImage, bool MonoImage) { System.Drawing.Bitmap TheImage; TheImage = null; if (GetButtonPicture(LargeImage, MonoImage, ref TheImage ) == true) { ImageConverter imgConverter = new ImageConverter() ; return imgConverter.ImageToIpicture(TheImage); } return null; } public bool CopyBitmap(bool LargeImage, bool MonoImage) { return true; } public bool Initialize(object Tool) { return true; } public bool UpdateToolStatus(object Tool, bool Enabled, bool Checked) { return true; } private bool GetButtonPicture(bool LargeImage, bool MonoImage, ref System.Drawing.Bitmap theImage ) { string s, s1; bool bRet = false; //define correct path to the icons here' // ' copy of these bmp files are located in TCVBNETTool directory // 'There are two ways to load images: from .Bmp file(s) or from .RES resource. // 'In this demo, we control the loading by a private variable. // Dim img As System.Drawing.Image // Dim thisApp As System.Reflection.Assembly // Dim file As System.IO.Stream System.Reflection.Assembly thisApp; System.IO.Stream file; System.Drawing.Image img; if (boolLoadFromBmp == true) { if (LargeImage) { img = System.Drawing.Image.FromFile(s1); //'"LargeIcon.bmp") bRet = true; } else { img = System.Drawing.Image.FromFile(s); //'"SmallIcon.bmp") bRet = true; } } else { if (LargeImage) { thisApp = System.Reflection.Assembly.GetExecutingAssembly(); //file = thisApp.GetManifestResourceStream("CSharpTCImage.101.bmp"); file = thisApp.GetManifestResourceStream("CSharpTCImage.101.bmp"); img = System.Drawing.Image.FromStream(file); bRet = true; } else { thisApp = System.Reflection.Assembly.GetExecutingAssembly(); file = thisApp.GetManifestResourceStream("CSharpTCImage.102.bmp"); img = System.Drawing.Image.FromStream(file); bRet = true; } } theImage = (System.Drawing.Bitmap)img; return bRet; } public bool InsertPicture(IMSIGX.IApplication gxApp, IMSIGX.IDrawing gxDr) { ITCImageManager pImageManager; string sname = "Test name"; // nameof the item in imagemanager picture's list double dx = 100; // size dx of the picture in drawing double dy = 100; // size dy of the picture in drawing bool bReference = true; // the picture added to the imagemanager as reference IMSIGX.IMatrix pMatrix = null; IMSIGX.View pView; IGraphic gxGr; IMSIGX.Properties pProps; IMSIGX.Property pProp; string sFileName = ""; string sExt = "Pictures (*.bmp;*.gif;*.jpg;*png;*.tif;*.pcx;*.ico;*.tga;*.wmf)|*.bmp;*.gif;*.jpg;*png;*.tif;*.pcx;*.ico;*.tga;*.wmf||"; System.Windows.Forms.OpenFileDialog fileDlg; //fileDlg.AddExtension ( sExt); fileDlg = new OpenFileDialog (); fileDlg.Filter = sExt; if (fileDlg.ShowDialog () != DialogResult.OK) { return false; } sFileName = fileDlg.FileName; object varPropName = "%#$AUX@_ShowImage"; object varVal = true; // Show picture //pImageManager = new TCIMAGELib.TCImageManagerClass(); pImageManager = (ITCImageManager)gxApp.CreateObject("TCImage.TCImageManager"); pMatrix = gxDr.UCS ; int lImageStyle = pImageManager.AddImageStyle(gxDr, sname, sFileName, bReference); gxGr = (IGraphic)pImageManager.CreateImageObject(gxDr, lImageStyle, pMatrix, dx, dy); pProps = gxGr.Properties ; pProp = pProps.get_Item(ref varPropName); pProp.set_Value(1, ref varVal); pView = gxDr.ActiveView ; pView.ZoomToExtents (); return false; } } public class ImageConverter : System.Windows.Forms.AxHost { public ImageConverter():base("59EE46BA-677D-4d20-BF10-8D8067CB8B33") { } public stdole.IPictureDisp ImageToIpicture(System.Drawing.Image image) { return (stdole.IPictureDisp)ImageConverter.GetIPictureDispFromPicture(image); } public System.Drawing.Image IPictureToImage(stdole.StdPicture picture) { return ImageConverter.GetPictureFromIPicture(picture); } } }